package com.study.ws.config.topmp;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * the stomp configuration for rabbit mq
 *
 * @author xl-9527
 * @since 2025/3/29
 **/
@Configuration(proxyBeanMethods = false)
public class StompRabbitMQConfiguration implements WebSocketMessageBrokerConfigurer {

    @Override
    public void registerStompEndpoints(final StompEndpointRegistry registry) {
        registry.addEndpoint("/ws/rabbitmq")
                .setAllowedOrigins("*");
    }

    @Override
    public void configureMessageBroker(final MessageBrokerRegistry registry) {
        registry.setApplicationDestinationPrefixes("/ws/mq/app");
        registry.enableSimpleBroker("/ws/mq/topic", "/ws/mq/user");
        registry.setUserDestinationPrefix("/ws/mq/user");
    }
}
